gpointer user_data)
{
gboolean cancelled = g_cancellable_is_cancelled (cancellable);
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
struct ChangeIconThemeData *data = user_data;
if (!g_slist_find (data->button->priv->change_icon_theme_cancellables, cancellable))
if (cancelled || error)
goto out;
- pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size);
+ surface = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size);
- if (pixbuf)
+ if (surface)
{
gint width = 0;
GtkTreeIter iter;
GtkTreePath *path;
- width = MAX (width, gdk_pixbuf_get_width (pixbuf));
+ width = MAX (width, data->button->priv->icon_size);
path = gtk_tree_row_reference_get_path (data->row_ref);
if (path)
gtk_tree_path_free (path);
gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
- ICON_COLUMN, pixbuf,
+ ICON_COLUMN, surface,
-1);
g_object_set (data->button->priv->icon_cell,
"width", width,
NULL);
}
- g_object_unref (pixbuf);
+ cairo_surface_destroy (surface);
}
out:
do
{
- GdkPixbuf *pixbuf = NULL;
+ cairo_surface_t *surface = NULL;
gchar type;
gpointer data;
info);
button->priv->change_icon_theme_cancellables =
g_slist_append (button->priv->change_icon_theme_cancellables, cancellable);
- pixbuf = NULL;
+ surface = NULL;
}
else
- /* Don't call get_info for remote paths to avoid latency and
- * auth dialogs.
- * If we switch to a better bookmarks file format (XBEL), we
- * should use mime info to get a better icon.
- */
- pixbuf = gtk_icon_theme_load_icon (theme, "folder-remote",
- priv->icon_size, 0, NULL);
+ {
+ /* Don't call get_info for remote paths to avoid latency and
+ * auth dialogs.
+ * If we switch to a better bookmarks file format (XBEL), we
+ * should use mime info to get a better icon.
+ */
+ surface = gtk_icon_theme_load_surface (theme, "folder-remote",
+ priv->icon_size,
+ gtk_widget_get_scale_factor (GTK_WIDGET (button)),
+ gtk_widget_get_window (GTK_WIDGET (button)),
+ 0, NULL);
+ }
}
break;
case ROW_TYPE_VOLUME:
if (data)
- pixbuf = _gtk_file_system_volume_render_icon (data,
- GTK_WIDGET (button),
- priv->icon_size,
- NULL);
+ {
+ surface = _gtk_file_system_volume_render_icon (data,
+ GTK_WIDGET (button),
+ priv->icon_size,
+ NULL);
+ }
+
break;
default:
continue;
break;
}
- if (pixbuf)
- width = MAX (width, gdk_pixbuf_get_width (pixbuf));
+ if (surface)
+ width = MAX (width, priv->icon_size);
gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
- ICON_COLUMN, pixbuf,
+ ICON_COLUMN, surface,
-1);
- if (pixbuf)
- g_object_unref (pixbuf);
+ if (surface)
+ cairo_surface_destroy (surface);
}
while (gtk_tree_model_iter_next (priv->model, &iter));
gpointer callback_data)
{
gboolean cancelled = g_cancellable_is_cancelled (cancellable);
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
GtkTreePath *path;
GtkTreeIter iter;
GCancellable *model_cancellable = NULL;
/* There was an error, leave the fallback name in there */
goto out;
- pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size);
+ surface = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size);
if (!data->label)
data->label = g_strdup (g_file_info_get_display_name (info));
is_folder = _gtk_file_info_consider_as_directory (info);
gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
- ICON_COLUMN, pixbuf,
+ ICON_COLUMN, surface,
DISPLAY_NAME_COLUMN, data->label,
IS_FOLDER_COLUMN, is_folder,
-1);
- if (pixbuf)
- g_object_unref (pixbuf);
+ if (surface)
+ cairo_surface_destroy (surface);
out:
g_object_unref (data->button);
gboolean cancelled = g_cancellable_is_cancelled (cancellable);
GtkTreeIter iter;
GtkTreePath *path;
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
GCancellable *model_cancellable = NULL;
struct ChangeIconThemeData *data = user_data;
gchar *name;
if (cancelled || error)
goto out;
- pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size);
-
- if (pixbuf)
+ surface = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size);
+ if (surface)
{
gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
- ICON_COLUMN, pixbuf,
+ ICON_COLUMN, surface,
-1);
- g_object_unref (pixbuf);
+ cairo_surface_destroy (surface);
}
gtk_tree_model_get (data->button->priv->model, &iter,
{
GtkFileSystemVolume *volume;
GtkTreeIter iter;
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
gchar *display_name;
volume = l->data;
}
}
- pixbuf = _gtk_file_system_volume_render_icon (volume,
- GTK_WIDGET (button),
- button->priv->icon_size,
- NULL);
+ surface = _gtk_file_system_volume_render_icon (volume,
+ GTK_WIDGET (button),
+ button->priv->icon_size,
+ NULL);
display_name = _gtk_file_system_volume_get_display_name (volume);
gtk_list_store_insert (store, &iter, pos);
gtk_list_store_set (store, &iter,
- ICON_COLUMN, pixbuf,
+ ICON_COLUMN, surface,
DISPLAY_NAME_COLUMN, display_name,
TYPE_COLUMN, ROW_TYPE_VOLUME,
DATA_COLUMN, _gtk_file_system_volume_ref (volume),
IS_FOLDER_COLUMN, TRUE,
-1);
- if (pixbuf)
- g_object_unref (pixbuf);
+ if (surface)
+ cairo_surface_destroy (surface);
g_free (display_name);
button->priv->n_volumes++;
{
gchar *label;
GtkIconTheme *icon_theme;
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface = NULL;
if (local_only)
continue;
label = _gtk_file_chooser_label_for_file (file);
icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (button)));
- pixbuf = gtk_icon_theme_load_icon (icon_theme, "folder-remote",
- button->priv->icon_size, 0, NULL);
+ surface = gtk_icon_theme_load_surface (icon_theme, "folder-remote",
+ button->priv->icon_size,
+ gtk_widget_get_scale_factor (GTK_WIDGET (button)),
+ gtk_widget_get_window (GTK_WIDGET (button)),
+ 0, NULL);
gtk_list_store_insert (store, &iter, pos);
gtk_list_store_set (store, &iter,
- ICON_COLUMN, pixbuf,
+ ICON_COLUMN, surface,
DISPLAY_NAME_COLUMN, label,
TYPE_COLUMN, ROW_TYPE_BOOKMARK,
DATA_COLUMN, g_object_ref (file),
-1);
g_free (label);
- g_object_unref (pixbuf);
+ if (surface)
+ cairo_surface_destroy (surface);
}
button->priv->n_bookmarks++;
{
gchar *label;
GtkIconTheme *icon_theme;
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
/* Don't call get_info for remote paths to avoid latency and
* auth dialogs.
icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (button)));
if (g_file_is_native (file))
- pixbuf = gtk_icon_theme_load_icon (icon_theme, "folder",
- button->priv->icon_size, 0, NULL);
+ surface = gtk_icon_theme_load_surface (icon_theme, "folder",
+ button->priv->icon_size,
+ gtk_widget_get_scale_factor (GTK_WIDGET (button)),
+ gtk_widget_get_window (GTK_WIDGET (button)),
+ 0, NULL);
else
- pixbuf = gtk_icon_theme_load_icon (icon_theme, "folder-remote",
- button->priv->icon_size, 0, NULL);
+ surface = gtk_icon_theme_load_surface (icon_theme, "folder-remote",
+ button->priv->icon_size,
+ gtk_widget_get_scale_factor (GTK_WIDGET (button)),
+ gtk_widget_get_window (GTK_WIDGET (button)),
+ 0, NULL);
gtk_list_store_set (store, &iter,
- ICON_COLUMN, pixbuf,
+ ICON_COLUMN, surface,
DISPLAY_NAME_COLUMN, label,
TYPE_COLUMN, ROW_TYPE_CURRENT_FOLDER,
DATA_COLUMN, g_object_ref (file),
-1);
g_free (label);
- g_object_unref (pixbuf);
+ if (surface)
+ cairo_surface_destroy (surface);
}
}
gpointer data)
{
gboolean cancelled = g_cancellable_is_cancelled (cancellable);
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
GtkFileChooserButton *button = data;
GtkFileChooserButtonPrivate *priv = button->priv;
gtk_label_set_text (GTK_LABEL (priv->label), g_file_info_get_display_name (info));
- pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (priv->image), priv->icon_size);
-
- gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), pixbuf);
- if (pixbuf)
- g_object_unref (pixbuf);
+ surface = _gtk_file_info_render_icon (info, GTK_WIDGET (priv->image), priv->icon_size);
+ gtk_image_set_from_surface (GTK_IMAGE (priv->image), surface);
+ if (surface)
+ cairo_surface_destroy (surface);
out:
emit_selection_changed_if_changing_selection (button);
base_file = _gtk_file_system_volume_get_root (volume);
if (base_file && g_file_equal (base_file, file))
{
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
label_text = _gtk_file_system_volume_get_display_name (volume);
- pixbuf = _gtk_file_system_volume_render_icon (volume,
- GTK_WIDGET (button),
- priv->icon_size,
- NULL);
- gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), pixbuf);
- if (pixbuf)
- g_object_unref (pixbuf);
+ surface = _gtk_file_system_volume_render_icon (volume,
+ GTK_WIDGET (button),
+ priv->icon_size,
+ NULL);
+ gtk_image_set_from_surface (GTK_IMAGE (priv->image), surface);
+ if (surface)
+ cairo_surface_destroy (surface);
}
if (base_file)
}
else
{
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
label_text = _gtk_bookmarks_manager_get_bookmark_label (button->priv->bookmarks_manager, file);
- pixbuf = gtk_icon_theme_load_icon (get_icon_theme (GTK_WIDGET (priv->image)),
- "text-x-generic",
- priv->icon_size, 0, NULL);
- gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), pixbuf);
- if (pixbuf)
- g_object_unref (pixbuf);
+ surface = gtk_icon_theme_load_surface (get_icon_theme (GTK_WIDGET (priv->image)),
+ "text-x-generic",
+ priv->icon_size,
+ gtk_widget_get_scale_factor (GTK_WIDGET (button)),
+ gtk_widget_get_window (GTK_WIDGET (button)),
+ 0, NULL);
+ gtk_image_set_from_surface (GTK_IMAGE (priv->image), surface);
+ if (surface)
+ cairo_surface_destroy (surface);
done_changing_selection = TRUE;
}
else
{
gtk_label_set_text (GTK_LABEL (priv->label), _(FALLBACK_DISPLAY_NAME));
- gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
+ gtk_image_set_from_surface (GTK_IMAGE (priv->image), NULL);
}
if (done_changing_selection)
return file;
}
-static GdkPixbuf *
-get_pixbuf_from_gicon (GIcon *icon,
- GtkWidget *widget,
- gint icon_size,
- GError **error)
+static cairo_surface_t *
+get_surface_from_gicon (GIcon *icon,
+ GtkWidget *widget,
+ gint icon_size,
+ GError **error)
{
GdkScreen *screen;
GtkIconTheme *icon_theme;
GtkIconInfo *icon_info;
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
screen = gtk_widget_get_screen (GTK_WIDGET (widget));
icon_theme = gtk_icon_theme_get_for_screen (screen);
- icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme,
- icon,
- icon_size,
- GTK_ICON_LOOKUP_USE_BUILTIN);
+ icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (icon_theme,
+ icon,
+ icon_size,
+ gtk_widget_get_scale_factor (widget),
+ GTK_ICON_LOOKUP_USE_BUILTIN);
if (!icon_info)
return NULL;
- pixbuf = gtk_icon_info_load_icon (icon_info, error);
+ surface = gtk_icon_info_load_surface (icon_info,
+ gtk_widget_get_window (widget), error);
+
g_object_unref (icon_info);
- return pixbuf;
+ return surface;
}
-GdkPixbuf *
+cairo_surface_t *
_gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume,
GtkWidget *widget,
gint icon_size,
GError **error)
{
GIcon *icon = NULL;
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
DEBUG ("volume_get_icon_name");
if (!icon)
return NULL;
- pixbuf = get_pixbuf_from_gicon (icon, widget, icon_size, error);
+ surface = get_surface_from_gicon (icon, widget, icon_size, error);
g_object_unref (icon);
- return pixbuf;
+ return surface;
}
GtkFileSystemVolume *
}
/* GFileInfo helper functions */
-GdkPixbuf *
+cairo_surface_t *
_gtk_file_info_render_icon (GFileInfo *info,
- GtkWidget *widget,
- gint icon_size)
+ GtkWidget *widget,
+ gint icon_size)
{
GIcon *icon;
- GdkPixbuf *pixbuf = NULL;
+ GdkPixbuf *pixbuf;
const gchar *thumbnail_path;
+ cairo_surface_t *surface = NULL;
+ int scale;
thumbnail_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
if (thumbnail_path)
- pixbuf = gdk_pixbuf_new_from_file_at_size (thumbnail_path,
- icon_size, icon_size,
- NULL);
+ {
+ scale = gtk_widget_get_scale_factor (widget);
+ pixbuf = gdk_pixbuf_new_from_file_at_size (thumbnail_path,
+ icon_size*scale, icon_size*scale,
+ NULL);
+
+ surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale,
+ gtk_widget_get_window (widget));
+ g_object_unref (pixbuf);
+ }
- if (!pixbuf)
+ if (!surface)
{
icon = g_file_info_get_icon (info);
if (icon)
- pixbuf = get_pixbuf_from_gicon (icon, widget, icon_size, NULL);
+ surface = get_surface_from_gicon (icon, widget, icon_size, NULL);
- if (!pixbuf)
+ if (!surface)
{
/* Use general fallback for all files without icon */
icon = g_themed_icon_new ("text-x-generic");
- pixbuf = get_pixbuf_from_gicon (icon, widget, icon_size, NULL);
+ surface = get_surface_from_gicon (icon, widget, icon_size, NULL);
g_object_unref (icon);
}
}
- return pixbuf;
+ return surface;
}
gboolean
GCancellable *get_info_cancellable;
- GdkPixbuf *root_icon;
- GdkPixbuf *home_icon;
- GdkPixbuf *desktop_icon;
+ cairo_surface_t *root_icon;
+ cairo_surface_t *home_icon;
+ cairo_surface_t *desktop_icon;
GdkWindow *event_window;
g_object_unref (path_bar->priv->desktop_file);
if (path_bar->priv->root_icon)
- g_object_unref (path_bar->priv->root_icon);
+ cairo_surface_destroy (path_bar->priv->root_icon);
if (path_bar->priv->home_icon)
- g_object_unref (path_bar->priv->home_icon);
+ cairo_surface_destroy (path_bar->priv->home_icon);
if (path_bar->priv->desktop_icon)
- g_object_unref (path_bar->priv->desktop_icon);
+ cairo_surface_destroy (path_bar->priv->desktop_icon);
if (path_bar->priv->file_system)
g_object_unref (path_bar->priv->file_system);
if (path_bar->priv->root_icon)
{
- g_object_unref (path_bar->priv->root_icon);
+ cairo_surface_destroy (path_bar->priv->root_icon);
path_bar->priv->root_icon = NULL;
}
if (path_bar->priv->home_icon)
{
- g_object_unref (path_bar->priv->home_icon);
+ cairo_surface_destroy (path_bar->priv->home_icon);
path_bar->priv->home_icon = NULL;
}
if (path_bar->priv->desktop_icon)
{
- g_object_unref (path_bar->priv->desktop_icon);
+ cairo_surface_destroy (path_bar->priv->desktop_icon);
path_bar->priv->desktop_icon = NULL;
}
gpointer user_data)
{
gboolean cancelled = g_cancellable_is_cancelled (cancellable);
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
struct SetButtonImageData *data = user_data;
if (cancellable != data->button_data->cancellable)
if (cancelled || error)
goto out;
- pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->path_bar),
+ surface = _gtk_file_info_render_icon (info, GTK_WIDGET (data->path_bar),
data->path_bar->priv->icon_size);
- gtk_image_set_from_pixbuf (GTK_IMAGE (data->button_data->image), pixbuf);
+ gtk_image_set_from_surface (GTK_IMAGE (data->button_data->image), surface);
switch (data->button_data->type)
{
case HOME_BUTTON:
if (data->path_bar->priv->home_icon)
- g_object_unref (pixbuf);
+ cairo_surface_destroy (surface);
else
- data->path_bar->priv->home_icon = pixbuf;
+ data->path_bar->priv->home_icon = surface;
break;
case DESKTOP_BUTTON:
if (data->path_bar->priv->desktop_icon)
- g_object_unref (pixbuf);
+ cairo_surface_destroy (surface);
else
- data->path_bar->priv->desktop_icon = pixbuf;
+ data->path_bar->priv->desktop_icon = surface;
break;
default:
if (path_bar->priv->root_icon != NULL)
{
- gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->priv->root_icon);
+ gtk_image_set_from_surface (GTK_IMAGE (button_data->image), path_bar->priv->root_icon);
break;
}
return;
path_bar->priv->root_icon = _gtk_file_system_volume_render_icon (volume,
- GTK_WIDGET (path_bar),
- path_bar->priv->icon_size,
- NULL);
+ GTK_WIDGET (path_bar),
+ path_bar->priv->icon_size,
+ NULL);
_gtk_file_system_volume_unref (volume);
- gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->priv->root_icon);
+ gtk_image_set_from_surface (GTK_IMAGE (button_data->image), path_bar->priv->root_icon);
break;
case HOME_BUTTON:
if (path_bar->priv->home_icon != NULL)
{
- gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->priv->home_icon);
+ gtk_image_set_from_surface (GTK_IMAGE (button_data->image), path_bar->priv->home_icon);
break;
}
case DESKTOP_BUTTON:
if (path_bar->priv->desktop_icon != NULL)
{
- gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->priv->desktop_icon);
+ gtk_image_set_from_surface (GTK_IMAGE (button_data->image), path_bar->priv->desktop_icon);
break;
}